﻿using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;

namespace Marmat.Forms
{
    public class TabFormPanelRenderer
    {
        public TabFormPanelRenderer(TabFormPanel TabFormPanel)
        {
            this.TabFormPanel = TabFormPanel;
        }

        public TabFormPanel TabFormPanel { get; set; }

        /// <summary>
    /// 绘制面板时触发
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnPaint(PaintEventArgs e)
        {
            if (this.TabFormPanel.BackgroundImage is object)
            {
                e.Graphics.DrawImage(this.TabFormPanel.BackgroundImage, new Rectangle(0, 0, this.TabFormPanel.Width, this.TabFormPanel.Height));
            }
            else
            {
                using (var Brush = new SolidBrush(this.TabFormPanel.BackColor))
                {
                    e.Graphics.FillRectangle(Brush, this.TabFormPanel.Rectangle);
                }
            }
        }

        /// <summary>
    /// 绘制面板时触发
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnPaint(PaintEventArgs e)
        {
            this.OnPaint(e);
        }

        /// <summary>
    /// 绘制窗口矩形框时触发
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        protected virtual void OnTabPaint(TabFormPaintEventArgs e)
        {
            using (var Brushes = new LinearGradientBrush(e.Rectangle, Color.FromArgb(50, 78, 111), Color.FromArgb(50, 78, 111), 90f))
            {
                if (ReferenceEquals(e.Form, this.TabFormPanel.SelectedForm))
                {
                    Brushes.LinearColors = new[] { Color.FromArgb(255, 242, 157), Color.FromArgb(255, 242, 157) };
                }
                else if (ReferenceEquals(e.Form, this.TabFormPanel.MouseMoveFrom))
                {
                    Brushes.LinearColors = new[] { Color.FromArgb(91, 113, 153), Color.FromArgb(91, 113, 153) };
                }

                var Path = GDI.GetRoundRectangle(e.Rectangle, this.TabFormPanel.ArcRadius);
                e.Graphics.FillPath(Brushes, Path);
            }
        }

        /// <summary>
    /// 绘制窗口矩形框时触发
    /// </summary>
    /// <param name="e"></param>
    /// <remarks></remarks>
        internal void RaiseOnTabPaint(TabFormPaintEventArgs e)
        {
            this.OnTabPaint(e);
        }
    }
}